<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/2/2
  Time: 10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<div class="modal-body">
  <div class="row">
    <div class="col-sm-12">
      <div class="form-group">

        <h5><label style="width:100%" for="h-input"> 提示：请职权信息文件
        </label>
        </h5>
      </div>
    </div>
    <div class="col-md-12">
      <form id="down_template" class="form-horizontal" action="" method="post">
        <fieldset>
          <div class="form-group">
            <label class="col-md-3 control-label" for="text-field">请上传职权信息文件</label>
            <div class="col-md-9">
              <input class="form-control" name="uploadify" id="file_upload_excel" placeholder=""
                     type="file"/>
              <a id="ajax_download_template" class="form-control" href="javascript:void(0);">下载模板</a>
            </div>
          </div>
        </fieldset>
      </form>
      <div id="import_excel_message_alert">

      </div>
    </div>
  </div>
</div>
<div class="modal-footer">
  <a href="#ajax!power.action" class="btn btn-primary" id="dialog-ok">确定</a>
  <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
</div>
<script>
  $(function() {
    $("#file_upload_excel").uploadify({
      height        : 30,
      multi : false,
      fileSizeLimit : '2MB',
      fileDataName : 'uploadify',
      progressData : 'percentage',
      'fileTypeDesc' : '格式:xlsx',     //描述
      fileTypeExts : '*.xlsx',
      buttonText : '选择excel文件上传',
      swf           : '../resource/com/js/plugin/uploadify/uploadify.swf',
      uploader      : 'ajax-import!powerUpload.action',
      width         : 140,
      onUploadStart:function(file){
        $("#import_excel_message_alert").empty();
        $('<div class="alert alert-info fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-info"></i><strong>正在努力为您处理！</strong> 导入过程分校验和导入两部分，请耐心等待...</div>').appendTo($("#import_message_alert"));

      },
      onUploadSuccess : function(file, data, response) {
        $("#import_excel_message_alert").empty();
        var json = jQuery.parseJSON(data);
        if(json && json.state == "200"){
          $('<div class="alert alert-success fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-check"></i><strong>上传完毕</strong> 数据导入成功！</div>').appendTo($("#import_excel_message_alert"));
          $(json.rows).each(function(index,map){
            $('<div class="alert alert-info fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-info"></i><strong>提醒！</strong> '+map.id+'</div>').appendTo($("#import_excel_message_alert"));
          });
          jQuery("#ajax_power_table").trigger("reloadGrid");
        }else{
          $('<div class="alert alert-info fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-info"></i><strong>上传失败！</strong> 请按照下面的错误清单调整CSV文件后重新上传！</div>').appendTo($("#import_excel_message_alert"));

          $(json.rows).each(function(index,map){
            $('<div class="alert alert-danger fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-times"></i><strong>错误！</strong> '+map.id+'</div>').appendTo($("#import_excel_message_alert"));
          });

        }
      }
    });
  });
  $("#dialog-ok").unbind("click").bind("click",function(){
    gDialog.fClose();
    loadURL("ajax!power.action", $('#content'));
  });
  //下载模板
  $("#ajax_download_template").click(function(){
    $("#down_template").attr("action","ajax-import!downTemplatePower.action").submit();
  });
</script>
